--pieces
local base = piece("base")
  body = piece("body") 
    local engines = piece("engines")
	  local engine1, engine2 = piece("engine1", "engine2")
    local turrets = {}
      local barrels = {} 
    for i = 1, 8 do
      turrets[i], barrels[i] = piece("turret"..i, "barrel"..i)
    end

scriptParams = {
  smokePieces = { body },
  enginePieces = { engine1, engine2 },
  smokeDelay = 200,
  maxRockAngleX = 5,
  maxRockAngleZ = 5,
  rockOnMove = true,

  weapons = {
    [1] = {
      turretTurnSpeed = 35,
      sleeveTurnSpeed = 25,
	    barrelRecoil = 5,
	    rockForce = 1000,
	    minPitch = -20,
	    --cegID = 1,
	    restores = true,
    },
    [2] = {
      turretTurnSpeed = 60,
      sleeveTurnSpeed = 30,
	    barrelRecoil = 3,
	    rockForce = 300,
	    minPitch = -20,
	    --cegID = 2,
	    restores = true,
    },
    [3] = {
      turretTurnSpeed = 60,
      sleeveTurnSpeed = 30,
	    barrelRecoil = 3,
	    rockForce = 300,
	    minPitch = -20,
	    --cegID = 2,
	    restores = true,
    }, 
    [4] = {
      turretTurnSpeed = 60,
      sleeveTurnSpeed = 30,
	    barrelRecoil = 3,
	    rockForce = 300,
	    minPitch = -20,
	    --cegID = 2,
	    restores = true,
    },     
    [5] = {	
      turretTurnSpeed = 120,
      sleeveTurnSpeed = 120,
	    minPitch = -20,
    },
    [6] = {	
      turretTurnSpeed = 120,
      sleeveTurnSpeed = 120,
	    minPitch = -20,
    },	    
    [7] = {	
      turretTurnSpeed = 180,
      sleeveTurnSpeed = 180,
	    minPitch = -20,
    },
    [8] = {	
      turretTurnSpeed = 180,
      sleeveTurnSpeed = 180,
	    minPitch = -20,
    },		
  } 
}



include "pre_scripts.lua"
  
for i = 1, 8 do
  setWeaponPieces(i, turrets[i],  barrels[i], barrels[i], barrels[i])  
end

include "scripts.lua"


function script.Killed (recentDamage, maxHealth)
  local severity = recentDamage / maxHealth
  
  if (severity <= 0.25) then
    Explode (body, SFX.NONE)
    Explode (engines, SFX.NONE)
    Explode (engine1, SFX.NONE)	
    Explode (engine2, SFX.NONE)
    for i = 1, 8 do	
      Explode (turrets[i], SFX.NONE)
      Explode (barrels[i], SFX.NONE)
    end  	
    return 1
  elseif (severity <= 0.50) then
    Explode (body, SFX.NONE)
    Explode (engines, SFX.NONE)
    Explode (engine1, SFX.SMOKE + SFX.FIRE)	
    Explode (engine2, SFX.SMOKE + SFX.FIRE)
    for i = 1, 8 do	
      Explode (turrets[i], SFX.SMOKE + SFX.FIRE)
      Explode (barrels[i], SFX.SMOKE + SFX.FIRE)
    end  	
    return 2
  else
    Explode (body, SFX.SHATTER)
    Explode (engines, SFX.SHATTER)
    Explode (engine1, SFX.SMOKE + SFX.FIRE + SFX.EXPLODE)	
    Explode (engine2, SFX.SMOKE + SFX.FIRE + SFX.EXPLODE)
    for i = 1, 8 do	
      Explode (turrets[i], SFX.SMOKE + SFX.FIRE + SFX.EXPLODE)
      Explode (barrels[i], SFX.SMOKE + SFX.FIRE + SFX.EXPLODE)
    end  
    return 3
  end
end